﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

using LowLevelGraphics.ColorSpaces;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// 
    /// </summary>
    public class Saettigung : BaseImageFilter
    {
        /// <summary>
        /// 
        /// </summary>
        public Saettigung()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_saettigung"></param>
        internal Saettigung(Saettigung _saettigung)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            Process((UnsafeBitmap)_bitmap.Clone(), _bitmap);
            return _bitmap;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_bitmapSource"></param>
        /// <param name="_bitmapDest"></param>
        /// <returns></returns>
        public UnsafeBitmap Process(UnsafeBitmap _bitmapSource, UnsafeBitmap _bitmapDest)
        {
            UnsafeBitmap bitmapSource = _bitmapSource;
            UnsafeBitmap bitmapDest = _bitmapDest;

            Color colorSource = Color.Transparent;
            Color colorDest = Color.Transparent;

            int y = 0;
            int x = 0;
            int nHeight = bitmapSource.Height;
            int nWidth = bitmapSource.Width;

            for (y = 0; y < nHeight; y++)
            {
                for (x = 0; x < nWidth; x++)
                {
                    colorSource = bitmapSource.GetPixel(x, y);
                    colorDest = bitmapDest.GetPixel(x, y);
                    HSV hsvSource = new HSV(colorSource);
                    HSV hsvDest = new HSV(colorDest);

                    //hsvDest.H = hsvDest.H;
                    hsvDest.S = ColorFunctions.PhotoshopSaturation(colorSource);
                    //hsvDest.L = hsvDest.L;
                    colorDest = hsvDest.ToColor();
                    bitmapDest.SetPixel(x, y, colorDest);
                }
            }
            bitmapSource.Dispose();
            bitmapDest.Dispose();
            return _bitmapDest;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new Saettigung(this);
        }
    }
}
